package org.edu.modules.jxgz.util;

import org.edu.common.util.SpringContextHolder;
import org.edu.modules.jxgz.entity.VeJwText;
import org.edu.modules.jxgz.service.IVeJwTextService;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 教务工具类
 * Created by Administrator on 2021/6/10.
 */
public class VeJwTextUtils {

    private static IVeJwTextService hqJwTextService = SpringContextHolder.getBean(IVeJwTextService.class);


    /**
     * 获取登录用户id
     *
     * @return
     */
    public static String getLoginUserId() {
        return "0";
    }


    private static Integer TERMINALID_DEFAULT = 1;

    /**
     * 保存富文本框内容并返回id
     *
     * @param text
     * @return
     */
    public static Integer add(String text) {
        VeJwText veJwText = new VeJwText();
        veJwText.setText(text);
        veJwText.setTerminalid(TERMINALID_DEFAULT);
        hqJwTextService.save(veJwText);
        return veJwText.getId();
    }


    /**
     * 修改内容
     *
     * @param id
     * @param text
     * @return
     */
    public static Integer update(Integer id, String text) {
        VeJwText veJwText = new VeJwText();
        veJwText.setId(id);
        veJwText.setText(text);
        hqJwTextService.updateById(veJwText);
        return veJwText.getId();
    }

    /**
     * 创建或修改富文本内容并返回Id
     *
     * @param id
     * @param text
     * @return
     */
    public static Integer addOrUpdate(Integer id,String text) {
        VeJwText veJwText = new VeJwText();
        veJwText.setId(id);
        veJwText.setText(text);
        veJwText.setTerminalid(TERMINALID_DEFAULT);
        hqJwTextService.saveOrUpdate(veJwText);
        return veJwText.getId();
    }


    /**
     * 通过Id获取富文本框内容
     *
     * @param id
     * @return
     */
    public static VeJwText getVeJwTextById(Integer id) {
        return hqJwTextService.getById(id);
    }


    public static Date stampToDate(String s) {
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long lt = new Long(s);
        Date date = new Date(lt);
//        res = simpleDateFormat.format(date);
        return date;
    }

}
